package com.rd.student.dashuju.sunwenzhuo.kaoshi;

import java.io.*;
import java.util.Objects;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) throws Exception {
        Writer writer = new FileWriter("player.txt");
        writer.write("杜兰特，勇士队" + "\n" + "威少，雷霆队" + "\n" + "库里，勇士队" + "\n" + "石破天，湖人队" + "\n" + "科比，湖人队");

        writer.close();
        File file = new File("player.txt");
        inquire(file);
    }

    public static void inquire(File file) throws Exception {

        BufferedReader reader = new BufferedReader(new FileReader(file));
        String player = null;
        String[] player1 = null;
        System.out.println("请输入您要查询的球员名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        while ((player = reader.readLine()) != null) {
            player1 = player.split("，");
            for (int i = 0; i < Objects.requireNonNull(player1).length; i++) {
                if (name.equals(player1[i])) {
                    System.out.println(name + "所属" + player1[i + 1]);
                    return;
                }
            }
        }
        System.out.println("没有该成员");
        reader.close();
    }

}
